//
//  PKRadioHeadView.m
//  PianKe
//
//  Created by lanou on 15/12/23.
//  Copyright © 2015年 KFC. All rights reserved.
//

#import "PKRadioHeadView.h"

@implementation PKRadioHeadView


- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.scrollerV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height / 2)];
        self.scrollerV.backgroundColor = [UIColor greenColor];
        // 设置属性
        // 设置滑动范围
        self.scrollerV.contentSize = CGSizeMake(frame.size.width * 4, 0);
        // 设置偏移量
        self.scrollerV.contentOffset = CGPointMake(frame.size.width, 0);
        // 关闭滚动条
        self.scrollerV.showsVerticalScrollIndicator = NO;
        self.scrollerV.showsHorizontalScrollIndicator = YES;
        // 设置整页滑动
        self.scrollerV.pagingEnabled = YES;
        // 设置回弹 (不能关,否则无法轮播)
        self.scrollerV.bounces = YES;
        // 设置代理 : 在控制器里设置
        [self addSubview:self.scrollerV];
        
        self.button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.button.frame = CGRectMake(0, 0, frame.size.width,self.scrollerV.height);
        self.button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.button1.frame = CGRectMake(frame.size.width, 0, frame.size.width,self.scrollerV.height);
        self.button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.button2.frame = CGRectMake(frame.size.width * 2, 0, frame.size.width,self.scrollerV.height);
        self.button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.button3.frame = CGRectMake(frame.size.width * 3, 0, frame.size.width,self.scrollerV.height);
    
        [self.scrollerV addSubview:self.button];
        [self.scrollerV addSubview:self.button1];
        [self.scrollerV addSubview:self.button2];
        [self.scrollerV addSubview:self.button3];
        
        // 分页控件
        self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(300, self.scrollerV.bottom - 10, 60,10)];
       // self.pageControl.backgroundColor = [UIColor redColor];
        self.pageControl.numberOfPages = 3;
        self.pageControl.currentPage = 0;
        self.pageControl.currentPageIndicatorTintColor = [UIColor yellowColor];
       // self.pageControl.pageIndicatorTintColor = [UIColor blackColor];
        
        [self addSubview:self.pageControl];
        
        
        self.buttonLeft = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.buttonLeft.frame = CGRectMake(self.scrollerV.left + 10, self.scrollerV.bottom + 10, (self.scrollerV.width - 20 - 5 * 2) / 3, self.scrollerV.height - 25 - 10);
        
        
        self.buttonMiddle = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.buttonMiddle.frame = CGRectMake(self.buttonLeft.right + 5, self.scrollerV.bottom + 10, (self.scrollerV.width - 20 - 5 * 2) / 3, self.scrollerV.height - 25 - 10);

        
        self.buttonRight = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.buttonRight.frame = CGRectMake(self.buttonMiddle.right + 5, self.scrollerV.bottom + 10, (self.scrollerV.width - 20 - 5 * 2) / 3 , self.scrollerV.height - 25 - 10);

        
        self.imageVLeft = [[UIImageView alloc] initWithFrame:self.buttonLeft.frame];
       
        self.imageVMiddle= [[UIImageView alloc] initWithFrame:self.buttonMiddle.frame];
        self.imageVRight = [[UIImageView alloc] initWithFrame:self.buttonRight.frame];
        
        
        [self addSubview: self.imageVLeft];
        [self addSubview: self.imageVMiddle];
        [self addSubview: self.imageVRight];
        
        [self addSubview:self.buttonLeft];
        [self addSubview:self.buttonMiddle];
        [self addSubview:self.buttonRight];
        
        
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.buttonLeft.left, self.buttonLeft.bottom + 10, 150, 25)];
        self.titleLabel.text = @"全部电台 All Radios";
        self.titleLabel.textColor = [UIColor grayColor];
        [self addSubview:self.titleLabel];

        self.lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.right, self.titleLabel.top + self.titleLabel.height / 2, frame.size.width - self.titleLabel.width - 20, 1)];
        self.lineLabel.backgroundColor = [UIColor grayColor];
        [self addSubview: self.lineLabel];
        
    }
    
    
    return self;
}


// 重写
-(void)setHotListArray:(NSArray *)hotListArray
{
    _hotListArray = hotListArray;
    
    // 赋值
    PKRadioModel *modelLeft = hotListArray[0];
    PKRadioModel *modelMiddle = hotListArray[1];
    PKRadioModel *modelRight = hotListArray[2];

  
    [self.imageVLeft sd_setImageWithURL:[NSURL URLWithString:modelLeft.coverimg] placeholderImage:nil];
    
    [self.imageVMiddle sd_setImageWithURL:[NSURL URLWithString:modelMiddle.coverimg] placeholderImage:nil];

    
    [self.imageVRight sd_setImageWithURL:[NSURL URLWithString:modelRight.coverimg] placeholderImage:nil];
   
}

- (void)setCarouselArray:(NSArray *)carouselArray
{
    _carouselArray = carouselArray;
    
    // 赋值
    PKRadioModel *model = carouselArray[0];
    PKRadioModel *model1 = carouselArray[1];
    PKRadioModel *model2 = carouselArray[2];
    
    // 这张是假图:
    [self.button sd_setBackgroundImageWithURL:[NSURL URLWithString:model2.img] forState:(UIControlStateNormal)];
    // 下面全是真图:
    [self.button1 sd_setBackgroundImageWithURL:[NSURL URLWithString:model.img] forState:(UIControlStateNormal)];
    [self.button2 sd_setBackgroundImageWithURL:[NSURL URLWithString:model1.img] forState:(UIControlStateNormal)];
    [self.button3 sd_setBackgroundImageWithURL:[NSURL URLWithString:model2.img] forState:(UIControlStateNormal)];
    
}




@end
